#include <linux/module.h>
#include <linux/lsm_hooks.h>
#include <linux/fs.h>
#include <linux/path.h>
#include <linux/dcache.h>

#include "get_symbol.h"
#include "write_perm.h"
#include "lsm.h"
#include "syscall_replace.h"
#include "get_os_info.h"

//初始化前配置
static int pre_init(void){
#if defined(__aarch64__)
	update_mapping_prot = (void *)kallsysm_lookup_name("update_mapping_prot");
	start_rodata = (unsigned long)kallsyms_lookup_name("__start_rodata");
	end_rodata = (unsigned long)kallsyms_lookup_name("__end_rodata");
#endif
	return 0;
}

//init函数
static int __init zds_init(void){
	int ret;

	//初始化前配置
	ret = pre_init();
	if(ret)
		goto err;

	//获取系统信息
	ret = get_os_info();
	if(ret)
		goto err;
	
	//符号初始化
	ret = fsym_init();
	if(ret)
		goto err;

	//lsm hook初始化
	ret = zds_hook_init();
	if(ret)
		goto err;

	//syscall初始化
	ret = syscall_replace_init();
	if(ret)
		goto err;

	printk("zds init success\n");
	return ret;
err:
	printk("zds init failed\n");
	return ret;
}

//exit函数
static void __exit zds_exit(void){
	zds_hook_exit();
	syscall_replace_exit();
	printk("zds exit success\n");
}

module_init(zds_init);
module_exit(zds_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("ZDS");
